<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" charset="UTF-8" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>收徒赚钱</title>
    <script src="${ctx}/js/jquery1.8.2.min.js"></script>
    <script src="${ctx}/js/vue.min.js"></script>
    <link rel="stylesheet" href="${ctx}/css/reset.css">
    <script src="${ctx}/js/changeSize.js"></script>
</head>
<style>
    html{
        background: rgb(254,224,111);
    }
    body{
        overflow-x: initial;
    <#--background-image: url("${ctx}/image/juejin/bag.png");-->
    <#--width: 100%;-->
    <#--height: auto;-->
    }
    .bg{
        width: 100%;
        height: auto;
        position: absolute;
        z-index: -1;
    }
    .user_data{
        padding: 2% 6%;
        font-size: 0.8rem;
    }
    .user_data img{
        width: 7%;
        height: 7%;
        float: left;
        /*height: 1.6rem;*/
    }
    .user_data span{
        height: 100%;
        margin-left: 0.3rem;
        float: left;
        margin-top: 1.5%;
        color: #FFE3E3;
    }
    .explain{
        font-size: 0.8rem;
        text-align: center;
        margin-top: 8%;
    }
    .explain img{
        width: 0.8rem;
    }
    .explain span{
        margin: 0 0.2rem;
        color: #fff;
    }
    .tit{
        text-align: center;
        margin-top: 14%;
        font-size: 1.6rem;
        color: #F95046;
        letter-spacing: 0.3rem;
    }
    .tit2{
        text-align: center;
        font-weight: 500;
        font-size: 0.7rem;
        color: #999999;
        margin-top: 5%;
        letter-spacing: 0.08rem;
    }
    .tit3{
        text-align: center;
        font-weight: 100;
        font-size: 0.5rem;
        color: #999999;
        margin-top: 5%;
        margin-bottom: 38%;
        letter-spacing: 0.08rem;
    }
    .user_name,.user_pad{
        padding: 0 1.6rem;
        text-align: center;
        margin-bottom: 1rem;
    }
    .user_name img{
        width: 1.5rem;
        padding: 0 0.4rem;
        margin-bottom: -0.6rem;
    }
    .user_name input{
        width: 14rem;
    }
    .user_name,.user_pad{
        width: 14rem;
        padding: 0.5rem 1rem;
        border-radius: 2rem;
        background: #fff;
        margin: auto;
        margin-bottom: 5%;
    }
    .user_name input,.user_pad input{
        border: 0;

    }
    .user_pad input{
        width: 6rem;
        float: left;
    }
    .user_pad img{
        width: 1.2rem;
        padding: 0 0.4rem;
        margin-bottom: -0.6rem;
    }
    .user_pad .btn_code{
        display: initial;
        width: 5rem;
        padding-left: 0.8rem;
        border-left: 0.05rem solid #CCCCCC;
        background: #fff;
        margin-left: 1.8rem;
        color: #FF5B5E;
        font-size: 0.8rem;
        font-weight: 500;
    }
    .btn_sub{
        text-align: center;
    }
    .btn_sub button{
        width: 16rem;
        height: 2.5rem;
        border-radius: 0.8rem;
        background: url("${ctx}/image/juejin/btn_gradient.png");
        background-size: 100%;
        color: #fff;
        text-align: center;
        border: 0;
        margin-top: 2%;
        line-height: 0;
    }
    .time{
        text-align: center;
        font-size: 0.8rem;
        margin: 1rem 0;
        color: #FF5B5E;
    }
    .tips{
        height: 1rem;
        color: red;
        font-size: 0.7rem;
        padding: 0 2.8rem;
    }
    .mask_wx{
        width: 100%;
        position: fixed;
        z-index: 999999;
        text-align: center;
        background: rgba(0,0,0,0.5)
    }
</style>
<body>
<div id="app">
    <div v-if="wx===true"  class="mask_wx" :style="{height:cheight}">
        <img src="${ctx}/image/juejin/wx.png" style="width: 17rem;margin-top: 2rem">
    </div>
    <img class="bg" src="${ctx}/image/juejin/bag.png">
    <div class="user_data">
        <img v-if="headimg" :src="headimg">
        <img v-else  src="${ctx}/image/juejin/head.png">
        <span>{{nick}}</span>
        <div style="clear: both"></div>
    </div>
    <p class="explain">
        <img src="${ctx}/image/juejin/horn.png">
        <span>Ta已经在[${appname}]赚了{{money}}元啦！</span>
    </p>
    <h2 class="tit">好料分享</h2>
    <h3 class="tit2">您的好友喊你来赚钱啦</h3>
    <h4 class="tit3">输入手机号就能参与</h4>
    <p class="user_name">
        <input v-model="phone" placeholder="请填写手机号" maxlength="11"/>
    </p>
    <div class="user_pad">
        <input placeholder="请输入验证码" v-model="code"/>
        <div class="btn_code" v-if="btn_code===1" @click="vcode()">{{btn_pad}}</div>
        <div class="btn_code" v-if="btn_code===2">{{code_time}}</div>
        <#--        <button v-if="btn_code===1" @click="vcode()">{{btn_pad}}</button>-->
        <#--        <button v-if="btn_code===2"></button>-->
    </div>
    <p class="tips"><span>{{err_tips}}</span></p>
    <p class="btn_sub"><button @click="sub()">立即参与</button></p>
    <p class="time">页面将在{{time}}后消失</p>

</div>
</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            phone:"",
            code:"",
            btn_pad:"发送验证码",
            time:"",
            err_tips:"",
            btn_code:1,
            code_time:60,
            headimg:'',
            nick:"",
            money:0,
            uuid:"",
            wx:false,
            cheight:'35rem'
        },

        mounted: function () {
            this.cheight=window.screen.height+"px"
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                this.wx=true
            } else {
                this.countdown(10,"");
                let incode= this.getQueryVariable("code");
                if (incode){
                    this.inviter(incode)
                }else {
                    window.location = '/taskjuejin/download?ty=2&not=2';
                }
            }
        },
        methods: {
            inviter(data){
                let that=this;
                $.ajax({
                    url: '/api/invite/inviter',
                    type: 'post',
                    data: {
                        code:data
                    },
                    dataType: "json",
                    success: function (res) {
                        // let data = JSON.parse(ajax.responseText);
                        // if (res.status==="200" || res.status===200){
                            if (res.status==="200" || res.status===200){
                                that.headimg=res.data.head;
                                that.nick=res.data.nick;
                                that.money=res.data.money/100;
                                that.uuid=res.data.uuid;
                            }else {
                                window.location = '/taskjuejin/download?ty=2&not=2';
                            }
                        // }else {
                        //     // window.location = '/taskjuejin/download?ty=2&not=1';
                        // }
                    },
                    error: function () {
                        that.err_tips="网络错误！"
                    }
                });
                // let ajax = new XMLHttpRequest();
                // ajax.open('post', 'http://192.168.1.40:8083/api/invite/inviter?code='+ data);
                // ajax.send();
                // try {
                //     ajax.onreadystatechange = function () {
                //         if (ajax.status === 200) {
                //             let data = JSON.parse(ajax.responseText);
                //             if (data.status==="200" || data.status===200){
                //                 that.headimg=data.data.head;
                //                 that.nick=data.data.nick;
                //                 that.money=data.data.money/100;
                //                 that.uuid=data.data.uuid;
                //             }else {
                //                 window.location = '/taskjuejin/download?ty=2&not=2';
                //             }
                //         } else {
                //             that.err_tips="网络错误！"
                //         }
                //     }
                // } catch (e) {
                //     that.err_tips="未知错误！"
                // }
            },
            countdown(time,type){
                let that=this;
                var maxtime = time * 60; //
                let gettime=function CountDown() {
                    if (maxtime >= 0) {
                        minutes = Math.floor(maxtime / 60);
                        seconds = Math.floor(maxtime % 60);
                        if(type==="codetime"){
                            if (seconds!==0){
                                that.code_time=seconds;
                            }
                        }else {
                            if (seconds<10){
                                that.time = minutes+":0"+seconds;
                            }else {
                                that.time = minutes+":"+seconds;
                            }
                        }
                        --maxtime;
                    } else{
                        clearInterval(timer);
                        console.log("时间到，结束!");
                        if (type==="codetime"){
                            that.btn_pad="重新发送"
                            that.btn_code=1;
                            that.code_time=60;
                        }else {
                            window.location = '/taskjuejin/download?ty=2&not=2';
                        }
                    }

                };
                timer = setInterval(gettime, 1000);
            },
            sub(){
                let that=this;
                if (that.phone){
                    if (that.code){
                        let that=this;
                        $.ajax({
                            url: '/api/invite/release',
                            type: 'post',
                            data: {
                                phone:that.phone,
                                code:that.code,
                                uuid:that.uuid
                            },
                            dataType: "json",
                            success: function (res) {
                                // let data = JSON.parse(ajax.responseText);
                                if (res.status==="200" || res.status===200){
                                    window.location = '/taskjuejin/download';
                                }else if (res.status==="204" || res.status===204) {

                                    window.location = '/taskjuejin/download?ty=2&not=1';
                                }else if (res.status==="201" || res.status===201){
                                    window.location = '/taskjuejin/download?ty=2&not=2';
                                }else {
                                    that.err_tips=res.message
                                    // window.location = '/taskjuejin/download?ty=2&not=1';
                                }
                            },
                            error: function () {
                                that.err_tips="网络错误！"
                            }
                        });
                        // let ajax = new XMLHttpRequest();
                        // ajax.open('post', 'http://192.168.1.40:8083/api/invite/release?phone=' + that.phone+"&code="+that.code+"&uuid="+that.uuid);
                        // ajax.send();
                        // try {
                        //     ajax.onreadystatechange = function () {
                        //         if (ajax.status === 200) {
                        //             let data = JSON.parse(ajax.responseText);
                        //             if (data.status==="200" || data.status===200){
                        //                 window.location = '/taskjuejin/download';
                        //             }else if (data.status==="204" || data.status===204) {
                        //                 window.location = '/taskjuejin/download?ty=2&not=1';
                        //             }else {
                        //                 window.location = '/taskjuejin/download?ty=2&not=2';
                        //             }
                        //         } else {
                        //             that.err_tips="网络错误！"
                        //         }
                        //     }
                        // } catch (e) {
                        //     that.err_tips="未知错误！"
                        // }
                    }else {
                        that.err_tips="请输入验证码！"
                    }
                }else {
                    that.err_tips="请输入电话号码！"
                }
            },
            vcode(){
                let that=this
                if (that.phone){
                    if (!(/^1[3456789]\d{9}$/.test(that.phone))){
                        that.err_tips="请输入正确的电话号码！"
                    }else {
                        $.ajax({
                            url: '/api/invite/valid',
                            type: 'post',
                            data: {
                                phone:that.phone
                            },
                            dataType: "json",
                            success: function (res) {
                                // let data = JSON.parse(ajax.responseText);
                                if (res.status==="200" || res.status===200){
                                    that.err_tips="";
                                    that.countdown(1,"codetime");
                                    that.btn_code=2;
                                }else {
                                    that.err_tips=res.message
                                }
                            },
                            error: function () {
                                that.err_tips="网络错误！"
                            }
                        });
                        // let ajax = new XMLHttpRequest();
                        // ajax.open('post', 'http://192.168.1.40:8083/api/invite/valid?phone=' + that.phone);
                        // ajax.send();
                        // try {
                        //     ajax.onreadystatechange = function () {
                        //         if (ajax.status === 200) {
                        //             let data = JSON.parse(ajax.responseText);
                        //             if (data.status==="200" || data.status===200){
                        //                 that.err_tips="";
                        //                 that.countdown(1,"codetime");
                        //                 that.btn_code=2;
                        //             }else {
                        //                 that.err_tips=data.message
                        //             }
                        //         } else {
                        //             that.err_tips="网络错误！"
                        //         }
                        //     }
                        // } catch (e) {
                        //
                        // }
                    }
                }else {
                    that.err_tips="请输入电话号码！"
                }
            },
            getQueryVariable(variable)
            {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if(pair[0] == variable){return pair[1];}
                }
                return(false);
            }
        }
    });

</script>
